<?php 
class addFileAction extends sfAction{
	public function execute($request){
		#$this->getContext()->getInstance()->getConfiguration()->loadHelpers('I18N');
		$action = $request->getParameter('contact', -1);
		$data = array();
		if($action == 'file'){
			if($request->isMethod('POST')){
				$data['file_original'] = basename($_FILES['add_file']['name']);
				$arr_ext = explode(".", $data['file_original']);
				$ext = $arr_ext[count($arr_ext)-1];
				#echo sfConfig::get('app_contact_filter');
				if(strpos(sfConfig::get('app_contact_filter'), strtolower($ext))!==false){
					$data['file_add'] = '/contact/'.str_replace('.', '_'.date('Y-m-d',time()).'.', $data['file_original']);
					
					if(file_exists(sfConfig::get('sf_upload_dir').$data['file_add'])){
						$data['file_add'] = str_replace('.', '_'.time().'.', $data['file_add']);
					}
					if(move_uploaded_file($_FILES['add_file']['tmp_name'], sfConfig::get('sf_upload_dir').$data['file_add'])){
						chmod($path, 0777);
						$data['error_code'] = 1;
					}
				}else{
					$data['error_code'] = 2; // type mismatch;
				}
			}
		}else{
			echo __('contact-add-file-fail');
			return sfView::NONE;
		}
		$this->setVar('data', $data);
	}
}